/**
 * Created by Administrator on 2017/9/22.
 */
require.config({
	paths: {
		"jquery": "lib/jquery/jquery-3.2.1",
		"jquery.cookie": "lib/jquery/jquery.cookie"
	}
});
require(["jquery", "jquery.cookie"], function ($) {
	$(function () {
		var $username = $("#login_username");
		var $upwd = $("#pass");
		var struserName = /^[a-zA-Z0-9_-]{4,16}$/;
		var strPassword = /^[a-zA-Z]\w{5,17}$/;
		$username.on("keyup", function () {
			if (!struserName.test($username.val())) {
				$(".nameuser").css("display", "block");
			}
			else $(".nameuser").hide();
		})
		// $username.on("blur",function () {
		// 	$(".nameuser").hide();
		// })
		$upwd.on("keyup", function () {
			if (!strPassword.test($upwd.val())) {
				$(".pass").css("display", "block");
			}
			else $(".pass").hide();
		})
		// $upwd.on("blur",function () {
		// 	$(".pass").hide();
		// })
		$("#btn").on("click", function () {
			if (struserName.test($username.val()) && strPassword.test($upwd.val())) {
				$.ajax({
					url: "http://localhost/miya/login.php",
					async: true,
					type: "post",
					data: {
						uuname: $("#login_username").val(),
						uupwd: $("#pass").val()
					},
					dataType: "json",
					success: function (res) {
						console.log(res);
						if (res.status == 1) {
							$.cookie("userName", $("#login_username").val(), {
								path: "/", expires: 7
							});
							window.location.href = "index.html";
						}
						else {
							alert(res.msg);
						}
						
					}
				})
				
			}
			// console.log($("#login_username").val());
			
		})
	})
})